﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.Globalization;

using CNCSoft.EWinform;
using CNCSoft.EWinform.ControlUtils;
using CNCSoft.EWinform.ERPApps;
using CNCSoft.EWinform.AGrid;
using CNCSoft.EData;

using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using Common;

namespace CNCSoft.ErpApps.TMS {

	/// <summary>
	/// Summary description for TienMatPhieuThuHocphi.
	/// </summary>
    public class KeHoachThuHocphi : System.Windows.Forms.Form
    {
        private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label8;
        private System.Windows.Forms.Label label9;
		private System.Windows.Forms.Label label10;
		internal System.Windows.Forms.Panel pnlButtons;
		internal System.Windows.Forms.Button cmdModify;
		internal System.Windows.Forms.Button cmdCancel;
		internal System.Windows.Forms.Button cmdPrint;
		internal System.Windows.Forms.Button cmdView;
		internal System.Windows.Forms.Button cmdDelete;
		internal System.Windows.Forms.Button cmdAddNew;
		private System.Windows.Forms.PictureBox pictureBox2;
        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.TextBox txtDienGiai;
		private System.Windows.Forms.TextBox txtSoChungTu;
        private System.Windows.Forms.ComboBox cboLyDoThu;
		private System.Windows.Forms.Button cmdXemTK;
        internal System.Windows.Forms.Button cmdUpdate;
		private System.Windows.Forms.ToolTip toolTip1;
		private System.Windows.Forms.ErrorProvider ep;
        private System.Windows.Forms.Label lblStatus;
		private System.Windows.Forms.Panel pnlNevigator;
		internal System.Windows.Forms.Button cmdMovePrevious;
		internal System.Windows.Forms.Button cmdMoveFirst;
		internal System.Windows.Forms.Button cmdMoveLast;
		internal System.Windows.Forms.Button cmdMoveNext;
        private CNCSoft.EWinform.ValidText txtNgayChungTu;
		private System.Windows.Forms.Label lblRecordInfo;
		private System.Windows.Forms.Panel pnlBottom;
		private System.Windows.Forms.PictureBox picboxNote;
        private System.Windows.Forms.PictureBox picboxHelp;
        private TextBox txtSoTien;
        private Label label11;
        private DataGrid dgridChiTietPT;
        private TextBox txtDotHocPhi;
        private Label label5;
        private Label label12;
        private TextBox txtMaNienHoc;
        private Label label7;
        private ComboBox cboLop;
        private DevExpress.XtraEditors.ListBoxControl list_DSHocSinh_Lop;
        private Panel panel1;
        private Label label1;
        private ValidText txtNgayDuKienThu;
		private System.ComponentModel.IContainer components;

        public KeHoachThuHocphi()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(KeHoachThuHocphi));
            this.label3 = new System.Windows.Forms.Label();
            this.txtDienGiai = new System.Windows.Forms.TextBox();
            this.label8 = new System.Windows.Forms.Label();
            this.txtSoChungTu = new System.Windows.Forms.TextBox();
            this.label9 = new System.Windows.Forms.Label();
            this.label10 = new System.Windows.Forms.Label();
            this.cboLyDoThu = new System.Windows.Forms.ComboBox();
            this.pnlButtons = new System.Windows.Forms.Panel();
            this.cmdModify = new System.Windows.Forms.Button();
            this.cmdCancel = new System.Windows.Forms.Button();
            this.cmdPrint = new System.Windows.Forms.Button();
            this.cmdView = new System.Windows.Forms.Button();
            this.cmdDelete = new System.Windows.Forms.Button();
            this.cmdAddNew = new System.Windows.Forms.Button();
            this.cmdUpdate = new System.Windows.Forms.Button();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
            this.txtSoTien = new System.Windows.Forms.TextBox();
            this.dgridChiTietPT = new System.Windows.Forms.DataGrid();
            this.txtDotHocPhi = new System.Windows.Forms.TextBox();
            this.cmdXemTK = new System.Windows.Forms.Button();
            this.picboxNote = new System.Windows.Forms.PictureBox();
            this.picboxHelp = new System.Windows.Forms.PictureBox();
            this.ep = new System.Windows.Forms.ErrorProvider(this.components);
            this.lblStatus = new System.Windows.Forms.Label();
            this.pnlBottom = new System.Windows.Forms.Panel();
            this.pnlNevigator = new System.Windows.Forms.Panel();
            this.cmdMoveFirst = new System.Windows.Forms.Button();
            this.cmdMovePrevious = new System.Windows.Forms.Button();
            this.cmdMoveNext = new System.Windows.Forms.Button();
            this.cmdMoveLast = new System.Windows.Forms.Button();
            this.lblRecordInfo = new System.Windows.Forms.Label();
            this.txtNgayChungTu = new CNCSoft.EWinform.ValidText();
            this.label11 = new System.Windows.Forms.Label();
            this.label5 = new System.Windows.Forms.Label();
            this.txtMaNienHoc = new System.Windows.Forms.TextBox();
            this.label7 = new System.Windows.Forms.Label();
            this.label12 = new System.Windows.Forms.Label();
            this.cboLop = new System.Windows.Forms.ComboBox();
            this.list_DSHocSinh_Lop = new DevExpress.XtraEditors.ListBoxControl();
            this.pictureBox2 = new System.Windows.Forms.PictureBox();
            this.panel1 = new System.Windows.Forms.Panel();
            this.label1 = new System.Windows.Forms.Label();
            this.txtNgayDuKienThu = new CNCSoft.EWinform.ValidText();
            this.pnlButtons.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.dgridChiTietPT)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.picboxNote)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.picboxHelp)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.ep)).BeginInit();
            this.pnlBottom.SuspendLayout();
            this.pnlNevigator.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.list_DSHocSinh_Lop)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
            this.panel1.SuspendLayout();
            this.SuspendLayout();
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(230, 195);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(57, 16);
            this.label3.TabIndex = 14;
            this.label3.Text = "Diễn giải";
            this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // txtDienGiai
            // 
            this.txtDienGiai.Location = new System.Drawing.Point(361, 192);
            this.txtDienGiai.MaxLength = 1000;
            this.txtDienGiai.Name = "txtDienGiai";
            this.txtDienGiai.Size = new System.Drawing.Size(588, 23);
            this.txtDienGiai.TabIndex = 15;
            this.txtDienGiai.Tag = "<LyDoThu> của <TenDonVi>";
            // 
            // label8
            // 
            this.label8.Anchor = System.Windows.Forms.AnchorStyles.None;
            this.label8.AutoSize = true;
            this.label8.Location = new System.Drawing.Point(311, 39);
            this.label8.Name = "label8";
            this.label8.Size = new System.Drawing.Size(36, 16);
            this.label8.TabIndex = 4;
            this.label8.Text = "Ngày";
            this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // txtSoChungTu
            // 
            this.txtSoChungTu.Anchor = System.Windows.Forms.AnchorStyles.None;
            this.txtSoChungTu.ForeColor = System.Drawing.Color.ForestGreen;
            this.txtSoChungTu.Location = new System.Drawing.Point(354, 6);
            this.txtSoChungTu.MaxLength = 15;
            this.txtSoChungTu.Name = "txtSoChungTu";
            this.txtSoChungTu.Size = new System.Drawing.Size(109, 23);
            this.txtSoChungTu.TabIndex = 3;
            this.txtSoChungTu.TabStop = false;
            this.txtSoChungTu.Text = "Số chứng từ";
            // 
            // label9
            // 
            this.label9.Anchor = System.Windows.Forms.AnchorStyles.None;
            this.label9.AutoSize = true;
            this.label9.Location = new System.Drawing.Point(311, 9);
            this.label9.Name = "label9";
            this.label9.Size = new System.Drawing.Size(23, 16);
            this.label9.TabIndex = 2;
            this.label9.Text = "Số";
            this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // label10
            // 
            this.label10.AutoSize = true;
            this.label10.Location = new System.Drawing.Point(230, 135);
            this.label10.Name = "label10";
            this.label10.Size = new System.Drawing.Size(60, 16);
            this.label10.TabIndex = 6;
            this.label10.Text = "Lý do thu";
            this.label10.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // cboLyDoThu
            // 
            this.cboLyDoThu.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cboLyDoThu.Location = new System.Drawing.Point(361, 131);
            this.cboLyDoThu.MaxDropDownItems = 15;
            this.cboLyDoThu.Name = "cboLyDoThu";
            this.cboLyDoThu.Size = new System.Drawing.Size(212, 24);
            this.cboLyDoThu.TabIndex = 7;
            this.cboLyDoThu.Validated += new System.EventHandler(this.cboLyDoThu_Validated);
            // 
            // pnlButtons
            // 
            this.pnlButtons.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
            this.pnlButtons.Controls.Add(this.cmdModify);
            this.pnlButtons.Controls.Add(this.cmdCancel);
            this.pnlButtons.Controls.Add(this.cmdPrint);
            this.pnlButtons.Controls.Add(this.cmdView);
            this.pnlButtons.Controls.Add(this.cmdDelete);
            this.pnlButtons.Controls.Add(this.cmdAddNew);
            this.pnlButtons.Controls.Add(this.cmdUpdate);
            this.pnlButtons.Location = new System.Drawing.Point(245, 493);
            this.pnlButtons.Name = "pnlButtons";
            this.pnlButtons.Size = new System.Drawing.Size(686, 36);
            this.pnlButtons.TabIndex = 0;
            // 
            // cmdModify
            // 
            this.cmdModify.Anchor = System.Windows.Forms.AnchorStyles.None;
            this.cmdModify.Cursor = System.Windows.Forms.Cursors.Hand;
            this.cmdModify.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
            this.cmdModify.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cmdModify.ForeColor = System.Drawing.Color.DodgerBlue;
            this.cmdModify.Image = ((System.Drawing.Image)(resources.GetObject("cmdModify.Image")));
            this.cmdModify.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.cmdModify.Location = new System.Drawing.Point(387, 3);
            this.cmdModify.Name = "cmdModify";
            this.cmdModify.Size = new System.Drawing.Size(80, 30);
            this.cmdModify.TabIndex = 4;
            this.cmdModify.Text = "&Sửa";
            this.cmdModify.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.cmdModify.Click += new System.EventHandler(this.cmdModify_Click);
            // 
            // cmdCancel
            // 
            this.cmdCancel.Anchor = System.Windows.Forms.AnchorStyles.None;
            this.cmdCancel.Cursor = System.Windows.Forms.Cursors.Hand;
            this.cmdCancel.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
            this.cmdCancel.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cmdCancel.ForeColor = System.Drawing.Color.DodgerBlue;
            this.cmdCancel.Image = ((System.Drawing.Image)(resources.GetObject("cmdCancel.Image")));
            this.cmdCancel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.cmdCancel.Location = new System.Drawing.Point(219, 3);
            this.cmdCancel.Name = "cmdCancel";
            this.cmdCancel.Size = new System.Drawing.Size(80, 30);
            this.cmdCancel.TabIndex = 2;
            this.cmdCancel.Text = "&Bỏ qua";
            this.cmdCancel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.cmdCancel.Click += new System.EventHandler(this.cmdCancel_Click);
            // 
            // cmdPrint
            // 
            this.cmdPrint.Anchor = System.Windows.Forms.AnchorStyles.None;
            this.cmdPrint.Cursor = System.Windows.Forms.Cursors.Hand;
            this.cmdPrint.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
            this.cmdPrint.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cmdPrint.ForeColor = System.Drawing.Color.DodgerBlue;
            this.cmdPrint.Image = ((System.Drawing.Image)(resources.GetObject("cmdPrint.Image")));
            this.cmdPrint.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.cmdPrint.Location = new System.Drawing.Point(555, 3);
            this.cmdPrint.Name = "cmdPrint";
            this.cmdPrint.Size = new System.Drawing.Size(80, 30);
            this.cmdPrint.TabIndex = 6;
            this.cmdPrint.Text = "&In";
            this.cmdPrint.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.toolTip1.SetToolTip(this.cmdPrint, "In phiếu thu");
            this.cmdPrint.Click += new System.EventHandler(this.cmdPrint_Click);
            // 
            // cmdView
            // 
            this.cmdView.Anchor = System.Windows.Forms.AnchorStyles.None;
            this.cmdView.Cursor = System.Windows.Forms.Cursors.Hand;
            this.cmdView.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
            this.cmdView.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cmdView.ForeColor = System.Drawing.Color.DodgerBlue;
            this.cmdView.Image = ((System.Drawing.Image)(resources.GetObject("cmdView.Image")));
            this.cmdView.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.cmdView.Location = new System.Drawing.Point(303, 3);
            this.cmdView.Name = "cmdView";
            this.cmdView.Size = new System.Drawing.Size(80, 30);
            this.cmdView.TabIndex = 3;
            this.cmdView.Text = "&Phiếu cũ";
            this.cmdView.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.toolTip1.SetToolTip(this.cmdView, "Xem, chọn lại phiếu cũ");
            this.cmdView.Click += new System.EventHandler(this.cmdView_Click);
            // 
            // cmdDelete
            // 
            this.cmdDelete.Anchor = System.Windows.Forms.AnchorStyles.None;
            this.cmdDelete.Cursor = System.Windows.Forms.Cursors.Hand;
            this.cmdDelete.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
            this.cmdDelete.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cmdDelete.ForeColor = System.Drawing.Color.DodgerBlue;
            this.cmdDelete.Image = ((System.Drawing.Image)(resources.GetObject("cmdDelete.Image")));
            this.cmdDelete.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.cmdDelete.Location = new System.Drawing.Point(471, 3);
            this.cmdDelete.Name = "cmdDelete";
            this.cmdDelete.Size = new System.Drawing.Size(80, 30);
            this.cmdDelete.TabIndex = 5;
            this.cmdDelete.Text = "&Xoá";
            this.cmdDelete.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.toolTip1.SetToolTip(this.cmdDelete, "Xóa phiếu thu hiện tại");
            this.cmdDelete.Click += new System.EventHandler(this.cmdDelete_Click);
            // 
            // cmdAddNew
            // 
            this.cmdAddNew.Anchor = System.Windows.Forms.AnchorStyles.None;
            this.cmdAddNew.Cursor = System.Windows.Forms.Cursors.Hand;
            this.cmdAddNew.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
            this.cmdAddNew.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cmdAddNew.ForeColor = System.Drawing.Color.DodgerBlue;
            this.cmdAddNew.Image = ((System.Drawing.Image)(resources.GetObject("cmdAddNew.Image")));
            this.cmdAddNew.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.cmdAddNew.Location = new System.Drawing.Point(51, 3);
            this.cmdAddNew.Name = "cmdAddNew";
            this.cmdAddNew.Size = new System.Drawing.Size(80, 30);
            this.cmdAddNew.TabIndex = 0;
            this.cmdAddNew.Text = "&Thêm";
            this.cmdAddNew.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.toolTip1.SetToolTip(this.cmdAddNew, "Thêm phiếu thu mới");
            this.cmdAddNew.Click += new System.EventHandler(this.cmdAddNew_Click_1);
            // 
            // cmdUpdate
            // 
            this.cmdUpdate.Anchor = System.Windows.Forms.AnchorStyles.None;
            this.cmdUpdate.Cursor = System.Windows.Forms.Cursors.Hand;
            this.cmdUpdate.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
            this.cmdUpdate.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cmdUpdate.ForeColor = System.Drawing.Color.DodgerBlue;
            this.cmdUpdate.Image = ((System.Drawing.Image)(resources.GetObject("cmdUpdate.Image")));
            this.cmdUpdate.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.cmdUpdate.Location = new System.Drawing.Point(135, 3);
            this.cmdUpdate.Name = "cmdUpdate";
            this.cmdUpdate.Size = new System.Drawing.Size(80, 30);
            this.cmdUpdate.TabIndex = 1;
            this.cmdUpdate.Text = "&Lưu";
            this.cmdUpdate.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.toolTip1.SetToolTip(this.cmdUpdate, "Lưu phiếu thu này");
            this.cmdUpdate.Click += new System.EventHandler(this.cmdSave_Click);
            // 
            // groupBox1
            // 
            this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.groupBox1.Location = new System.Drawing.Point(1, 109);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(995, 8);
            this.groupBox1.TabIndex = 6;
            this.groupBox1.TabStop = false;
            // 
            // txtSoTien
            // 
            this.txtSoTien.BackColor = System.Drawing.SystemColors.Info;
            this.txtSoTien.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.txtSoTien.ForeColor = System.Drawing.Color.IndianRed;
            this.txtSoTien.Location = new System.Drawing.Point(361, 163);
            this.txtSoTien.Name = "txtSoTien";
            this.txtSoTien.ReadOnly = true;
            this.txtSoTien.Size = new System.Drawing.Size(212, 23);
            this.txtSoTien.TabIndex = 13;
            this.txtSoTien.TabStop = false;
            this.txtSoTien.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            this.toolTip1.SetToolTip(this.txtSoTien, "Số tiền VND = Số tiền nguyên tệ x Tỉ giá");
            // 
            // dgridChiTietPT
            // 
            this.dgridChiTietPT.AllowSorting = false;
            this.dgridChiTietPT.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.dgridChiTietPT.CaptionText = "Chi tiết thu";
            this.dgridChiTietPT.CaptionVisible = false;
            this.dgridChiTietPT.DataMember = "";
            this.dgridChiTietPT.HeaderForeColor = System.Drawing.SystemColors.ControlText;
            this.dgridChiTietPT.Location = new System.Drawing.Point(233, 232);
            this.dgridChiTietPT.Name = "dgridChiTietPT";
            this.dgridChiTietPT.Size = new System.Drawing.Size(749, 248);
            this.dgridChiTietPT.TabIndex = 16;
            this.toolTip1.SetToolTip(this.dgridChiTietPT, "Có thể nhập thêm chi tiết Thu ở đây (thêm dòng), 1 NỢ nhiều CÓ");
            // 
            // txtDotHocPhi
            // 
            this.txtDotHocPhi.BackColor = System.Drawing.Color.White;
            this.txtDotHocPhi.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.txtDotHocPhi.ForeColor = System.Drawing.SystemColors.WindowText;
            this.txtDotHocPhi.Location = new System.Drawing.Point(648, 132);
            this.txtDotHocPhi.Name = "txtDotHocPhi";
            this.txtDotHocPhi.Size = new System.Drawing.Size(64, 23);
            this.txtDotHocPhi.TabIndex = 9;
            this.txtDotHocPhi.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            this.toolTip1.SetToolTip(this.txtDotHocPhi, "Số tiền VND = Số tiền nguyên tệ x Tỉ giá");
            this.txtDotHocPhi.Validating += new System.ComponentModel.CancelEventHandler(this.txtThangHocPhi_Validating);
            // 
            // cmdXemTK
            // 
            this.cmdXemTK.Cursor = System.Windows.Forms.Cursors.Hand;
            this.cmdXemTK.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
            this.cmdXemTK.Font = new System.Drawing.Font("Tahoma", 8.25F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Underline))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cmdXemTK.ForeColor = System.Drawing.Color.DodgerBlue;
            this.cmdXemTK.Image = ((System.Drawing.Image)(resources.GetObject("cmdXemTK.Image")));
            this.cmdXemTK.Location = new System.Drawing.Point(955, 192);
            this.cmdXemTK.Name = "cmdXemTK";
            this.cmdXemTK.Size = new System.Drawing.Size(28, 22);
            this.cmdXemTK.TabIndex = 17;
            this.cmdXemTK.TabStop = false;
            this.toolTip1.SetToolTip(this.cmdXemTK, "Xem chi tiết tài khoản !.");
            this.cmdXemTK.Click += new System.EventHandler(this.cmdXemTK_Click);
            // 
            // picboxNote
            // 
            this.picboxNote.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.picboxNote.Cursor = System.Windows.Forms.Cursors.Hand;
            this.picboxNote.Image = ((System.Drawing.Image)(resources.GetObject("picboxNote.Image")));
            this.picboxNote.Location = new System.Drawing.Point(942, 8);
            this.picboxNote.Name = "picboxNote";
            this.picboxNote.Size = new System.Drawing.Size(20, 18);
            this.picboxNote.TabIndex = 384;
            this.picboxNote.TabStop = false;
            this.toolTip1.SetToolTip(this.picboxNote, "Ghi chú !.");
            this.picboxNote.Click += new System.EventHandler(this.cmdNote_Click);
            // 
            // picboxHelp
            // 
            this.picboxHelp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.picboxHelp.Cursor = System.Windows.Forms.Cursors.Hand;
            this.picboxHelp.Image = ((System.Drawing.Image)(resources.GetObject("picboxHelp.Image")));
            this.picboxHelp.Location = new System.Drawing.Point(966, 8);
            this.picboxHelp.Name = "picboxHelp";
            this.picboxHelp.Size = new System.Drawing.Size(20, 18);
            this.picboxHelp.TabIndex = 383;
            this.picboxHelp.TabStop = false;
            this.toolTip1.SetToolTip(this.picboxHelp, "Trợ giúp !.");
            this.picboxHelp.Click += new System.EventHandler(this.picboxHelp_Click);
            // 
            // ep
            // 
            this.ep.ContainerControl = this;
            this.ep.Icon = ((System.Drawing.Icon)(resources.GetObject("ep.Icon")));
            // 
            // lblStatus
            // 
            this.lblStatus.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lblStatus.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.lblStatus.Location = new System.Drawing.Point(256, 6);
            this.lblStatus.Name = "lblStatus";
            this.lblStatus.Size = new System.Drawing.Size(461, 18);
            this.lblStatus.TabIndex = 341;
            this.lblStatus.Text = "Form đã khởi tạo thành công.";
            this.lblStatus.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // pnlBottom
            // 
            this.pnlBottom.Controls.Add(this.picboxNote);
            this.pnlBottom.Controls.Add(this.picboxHelp);
            this.pnlBottom.Controls.Add(this.lblStatus);
            this.pnlBottom.Controls.Add(this.pnlNevigator);
            this.pnlBottom.Dock = System.Windows.Forms.DockStyle.Bottom;
            this.pnlBottom.Location = new System.Drawing.Point(0, 539);
            this.pnlBottom.Name = "pnlBottom";
            this.pnlBottom.Size = new System.Drawing.Size(997, 28);
            this.pnlBottom.TabIndex = 7;
            // 
            // pnlNevigator
            // 
            this.pnlNevigator.Controls.Add(this.cmdMoveFirst);
            this.pnlNevigator.Controls.Add(this.cmdMovePrevious);
            this.pnlNevigator.Controls.Add(this.cmdMoveNext);
            this.pnlNevigator.Controls.Add(this.cmdMoveLast);
            this.pnlNevigator.Controls.Add(this.lblRecordInfo);
            this.pnlNevigator.Dock = System.Windows.Forms.DockStyle.Left;
            this.pnlNevigator.Location = new System.Drawing.Point(0, 0);
            this.pnlNevigator.Name = "pnlNevigator";
            this.pnlNevigator.Size = new System.Drawing.Size(241, 28);
            this.pnlNevigator.TabIndex = 343;
            // 
            // cmdMoveFirst
            // 
            this.cmdMoveFirst.Cursor = System.Windows.Forms.Cursors.Hand;
            this.cmdMoveFirst.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
            this.cmdMoveFirst.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cmdMoveFirst.ForeColor = System.Drawing.Color.Maroon;
            this.cmdMoveFirst.Image = ((System.Drawing.Image)(resources.GetObject("cmdMoveFirst.Image")));
            this.cmdMoveFirst.Location = new System.Drawing.Point(19, 4);
            this.cmdMoveFirst.Name = "cmdMoveFirst";
            this.cmdMoveFirst.Size = new System.Drawing.Size(24, 20);
            this.cmdMoveFirst.TabIndex = 0;
            this.cmdMoveFirst.Click += new System.EventHandler(this.cmdMoveFirst_Click);
            // 
            // cmdMovePrevious
            // 
            this.cmdMovePrevious.Cursor = System.Windows.Forms.Cursors.Hand;
            this.cmdMovePrevious.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
            this.cmdMovePrevious.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cmdMovePrevious.ForeColor = System.Drawing.Color.Maroon;
            this.cmdMovePrevious.Image = ((System.Drawing.Image)(resources.GetObject("cmdMovePrevious.Image")));
            this.cmdMovePrevious.Location = new System.Drawing.Point(47, 4);
            this.cmdMovePrevious.Name = "cmdMovePrevious";
            this.cmdMovePrevious.Size = new System.Drawing.Size(24, 20);
            this.cmdMovePrevious.TabIndex = 1;
            this.cmdMovePrevious.Click += new System.EventHandler(this.cmdMovePrevious_Click);
            // 
            // cmdMoveNext
            // 
            this.cmdMoveNext.Cursor = System.Windows.Forms.Cursors.Hand;
            this.cmdMoveNext.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
            this.cmdMoveNext.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cmdMoveNext.ForeColor = System.Drawing.Color.Maroon;
            this.cmdMoveNext.Image = ((System.Drawing.Image)(resources.GetObject("cmdMoveNext.Image")));
            this.cmdMoveNext.Location = new System.Drawing.Point(79, 4);
            this.cmdMoveNext.Name = "cmdMoveNext";
            this.cmdMoveNext.Size = new System.Drawing.Size(24, 20);
            this.cmdMoveNext.TabIndex = 4;
            this.cmdMoveNext.Click += new System.EventHandler(this.cmdMoveNext_Click);
            // 
            // cmdMoveLast
            // 
            this.cmdMoveLast.Cursor = System.Windows.Forms.Cursors.Hand;
            this.cmdMoveLast.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
            this.cmdMoveLast.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cmdMoveLast.ForeColor = System.Drawing.Color.Maroon;
            this.cmdMoveLast.Image = ((System.Drawing.Image)(resources.GetObject("cmdMoveLast.Image")));
            this.cmdMoveLast.Location = new System.Drawing.Point(107, 4);
            this.cmdMoveLast.Name = "cmdMoveLast";
            this.cmdMoveLast.Size = new System.Drawing.Size(24, 20);
            this.cmdMoveLast.TabIndex = 0;
            this.cmdMoveLast.Click += new System.EventHandler(this.cmdMoveLast_Click);
            // 
            // lblRecordInfo
            // 
            this.lblRecordInfo.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.lblRecordInfo.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lblRecordInfo.Location = new System.Drawing.Point(135, 4);
            this.lblRecordInfo.Name = "lblRecordInfo";
            this.lblRecordInfo.Size = new System.Drawing.Size(96, 20);
            this.lblRecordInfo.TabIndex = 344;
            this.lblRecordInfo.Text = "Record Info";
            this.lblRecordInfo.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // txtNgayChungTu
            // 
            this.txtNgayChungTu.Anchor = System.Windows.Forms.AnchorStyles.None;
            this.txtNgayChungTu.ClearTime = false;
            this.txtNgayChungTu.DateDelimiter = "/";
            this.txtNgayChungTu.DateInputFormat = CNCSoft.EUtilities.DateFormat.DDMMYYYY;
            this.txtNgayChungTu.DateOutputFormat = CNCSoft.EUtilities.DateFormat.DDMMYYYY;
            this.txtNgayChungTu.FieldReference = null;
            this.txtNgayChungTu.Location = new System.Drawing.Point(354, 36);
            this.txtNgayChungTu.MaskEdit = "";
            this.txtNgayChungTu.MaxLength = 15;
            this.txtNgayChungTu.MessageLanguage = CNCSoft.EWinform.ValidText.MessageLanguages.Vietnamese;
            this.txtNgayChungTu.Name = "txtNgayChungTu";
            this.txtNgayChungTu.RegExPattern = CNCSoft.EWinform.ValidText.RegularExpressionModes.AutomatedDate;
            this.txtNgayChungTu.Required = false;
            this.txtNgayChungTu.ShowErrorIcon = true;
            this.txtNgayChungTu.Size = new System.Drawing.Size(109, 23);
            this.txtNgayChungTu.TabIndex = 5;
            this.txtNgayChungTu.TabStop = false;
            this.txtNgayChungTu.ValidationMode = CNCSoft.EWinform.ValidText.ValidationModes.None;
            this.txtNgayChungTu.ValidText = "0123456789/ ";
            this.txtNgayChungTu.YearPrefix = ((short)(20));
            // 
            // label11
            // 
            this.label11.AutoSize = true;
            this.label11.Location = new System.Drawing.Point(230, 166);
            this.label11.Name = "label11";
            this.label11.Size = new System.Drawing.Size(48, 16);
            this.label11.TabIndex = 12;
            this.label11.Text = "Số tiền";
            this.label11.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // label5
            // 
            this.label5.AutoSize = true;
            this.label5.Location = new System.Drawing.Point(606, 135);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(28, 16);
            this.label5.TabIndex = 8;
            this.label5.Text = "Đợt";
            this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // txtMaNienHoc
            // 
            this.txtMaNienHoc.Location = new System.Drawing.Point(78, 54);
            this.txtMaNienHoc.MaxLength = 50;
            this.txtMaNienHoc.Name = "txtMaNienHoc";
            this.txtMaNienHoc.Size = new System.Drawing.Size(132, 23);
            this.txtMaNienHoc.TabIndex = 2;
            this.txtMaNienHoc.TabStop = false;
            this.txtMaNienHoc.TextChanged += new System.EventHandler(this.txtMaNienHoc_TextChanged);
            this.txtMaNienHoc.Validated += new System.EventHandler(this.txtMaNienHoc_Validated);
            // 
            // label7
            // 
            this.label7.AutoSize = true;
            this.label7.Location = new System.Drawing.Point(16, 57);
            this.label7.Name = "label7";
            this.label7.Size = new System.Drawing.Size(57, 16);
            this.label7.TabIndex = 1;
            this.label7.Text = "Niên học";
            this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // label12
            // 
            this.label12.AutoSize = true;
            this.label12.Location = new System.Drawing.Point(16, 87);
            this.label12.Name = "label12";
            this.label12.Size = new System.Drawing.Size(28, 16);
            this.label12.TabIndex = 3;
            this.label12.Text = "Lớp";
            this.label12.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // cboLop
            // 
            this.cboLop.FormattingEnabled = true;
            this.cboLop.Location = new System.Drawing.Point(78, 83);
            this.cboLop.Name = "cboLop";
            this.cboLop.Size = new System.Drawing.Size(132, 24);
            this.cboLop.TabIndex = 4;
            this.cboLop.SelectedIndexChanged += new System.EventHandler(this.cboLop_SelectedIndexChanged);
            // 
            // list_DSHocSinh_Lop
            // 
            this.list_DSHocSinh_Lop.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)));
            this.list_DSHocSinh_Lop.DisplayMember = "HoTen";
            this.list_DSHocSinh_Lop.Location = new System.Drawing.Point(12, 131);
            this.list_DSHocSinh_Lop.Name = "list_DSHocSinh_Lop";
            this.list_DSHocSinh_Lop.Size = new System.Drawing.Size(198, 395);
            this.list_DSHocSinh_Lop.TabIndex = 5;
            this.list_DSHocSinh_Lop.ValueMember = "MaHocTap";
            this.list_DSHocSinh_Lop.SelectedIndexChanged += new System.EventHandler(this.list_DSHocSinh_Lop_SelectedIndexChanged);
            // 
            // pictureBox2
            // 
            this.pictureBox2.Dock = System.Windows.Forms.DockStyle.Top;
            //this.pictureBox2.Image = global::CNCSoft.ErpApps.TMS.Properties.Resources.frm_KeHoachThuHocPhi;
            this.pictureBox2.Location = new System.Drawing.Point(0, 0);
            this.pictureBox2.Name = "pictureBox2";
            this.pictureBox2.Size = new System.Drawing.Size(997, 45);
            this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.pictureBox2.TabIndex = 333;
            this.pictureBox2.TabStop = false;
            // 
            // panel1
            // 
            this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.panel1.Controls.Add(this.txtSoChungTu);
            this.panel1.Controls.Add(this.label8);
            this.panel1.Controls.Add(this.label9);
            this.panel1.Controls.Add(this.txtNgayChungTu);
            this.panel1.Location = new System.Drawing.Point(107, 51);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(889, 66);
            this.panel1.TabIndex = 335;
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(729, 134);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(103, 16);
            this.label1.TabIndex = 10;
            this.label1.Text = "Ngày dụ kiến thu";
            this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // txtNgayDuKienThu
            // 
            this.txtNgayDuKienThu.ClearTime = false;
            this.txtNgayDuKienThu.DateDelimiter = "/";
            this.txtNgayDuKienThu.DateInputFormat = CNCSoft.EUtilities.DateFormat.DDMMYYYY;
            this.txtNgayDuKienThu.DateOutputFormat = CNCSoft.EUtilities.DateFormat.DDMMYYYY;
            this.txtNgayDuKienThu.FieldReference = null;
            this.txtNgayDuKienThu.Location = new System.Drawing.Point(838, 131);
            this.txtNgayDuKienThu.MaskEdit = "";
            this.txtNgayDuKienThu.MaxLength = 15;
            this.txtNgayDuKienThu.MessageLanguage = CNCSoft.EWinform.ValidText.MessageLanguages.Vietnamese;
            this.txtNgayDuKienThu.Name = "txtNgayDuKienThu";
            this.txtNgayDuKienThu.RegExPattern = CNCSoft.EWinform.ValidText.RegularExpressionModes.AutomatedDate;
            this.txtNgayDuKienThu.Required = false;
            this.txtNgayDuKienThu.ShowErrorIcon = true;
            this.txtNgayDuKienThu.Size = new System.Drawing.Size(111, 23);
            this.txtNgayDuKienThu.TabIndex = 11;
            this.txtNgayDuKienThu.ValidationMode = CNCSoft.EWinform.ValidText.ValidationModes.None;
            this.txtNgayDuKienThu.ValidText = "0123456789/ ";
            this.txtNgayDuKienThu.YearPrefix = ((short)(20));
            // 
            // KeHoachThuHocphi
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(6, 16);
            this.BackColor = System.Drawing.Color.WhiteSmoke;
            this.ClientSize = new System.Drawing.Size(997, 567);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.list_DSHocSinh_Lop);
            this.Controls.Add(this.txtNgayDuKienThu);
            this.Controls.Add(this.cboLop);
            this.Controls.Add(this.label12);
            this.Controls.Add(this.txtMaNienHoc);
            this.Controls.Add(this.label7);
            this.Controls.Add(this.txtDotHocPhi);
            this.Controls.Add(this.label5);
            this.Controls.Add(this.dgridChiTietPT);
            this.Controls.Add(this.txtSoTien);
            this.Controls.Add(this.label11);
            this.Controls.Add(this.label10);
            this.Controls.Add(this.txtDienGiai);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.cmdXemTK);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.pictureBox2);
            this.Controls.Add(this.pnlButtons);
            this.Controls.Add(this.cboLyDoThu);
            this.Controls.Add(this.pnlBottom);
            this.Controls.Add(this.panel1);
            this.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.KeyPreview = true;
            this.MinimumSize = new System.Drawing.Size(833, 539);
            this.Name = "KeHoachThuHocphi";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Tag = "";
            this.Text = "Kế toán";
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            this.Load += new System.EventHandler(this.KeHoachThuHocphi_Load);
            this.Click += new System.EventHandler(this.TienMatPhieuThuHocphi_Click);
            this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.TienMatPhieuThuHocphi_KeyDown);
            this.pnlButtons.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.dgridChiTietPT)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.picboxNote)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.picboxHelp)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.ep)).EndInit();
            this.pnlBottom.ResumeLayout(false);
            this.pnlNevigator.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.list_DSHocSinh_Lop)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
            this.panel1.ResumeLayout(false);
            this.panel1.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

		}
		#endregion

		#region [ Command Events ]
		    bool cancelHandlers;
		    KeHoachThuHocphiData ptData;
		    BindingManagerBase bmb;
        
            //Cac bien phan quyen tren form
            bool DuocQuyenThem = true;
            bool DuocQuyenSua = true;
            bool DuocQuyenXoa = true;

		#endregion

		private void KeHoachThuHocphi_Load(object sender, System.EventArgs e) {
			cancelHandlers = true;
			try {
				ptData = new KeHoachThuHocphiData();

				intiDatabinding();

                ptData.getTable(KeHoachThuHocphiData.TL.TienMatPT_CT).ColumnChanged += new DataColumnChangeEventHandler(TienMatPhieuThuHocphi_ColumnChanged);
                ptData.getTable(KeHoachThuHocphiData.TL.TienMatPT_CT).RowDeleted += new DataRowChangeEventHandler(TienMatPhieuThuHocphi_RowDeleted);
				
				bmb = this.BindingContext[ptData.getDataSet(), "TienMatPT"];

				bmb.PositionChanged +=new EventHandler(bmb_PositionChanged);

			} catch {
				MessageBox.Show(this, RS.ERROR_LOAD_FORM, RS.ERROR_LOAD_FORM_CAPTION, 
					MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
			} finally {
				cancelHandlers = false;
			}

            PublicFunction.PhanQuyenForm(this.Name, GlobalVariable.WSInfo.UserID, out DuocQuyenThem, out DuocQuyenSua, out DuocQuyenXoa);

            if (DuocQuyenThem)
            {
                //cmdAddNew_Click(cmdAddNew, e);
                setEditMode(false);
                sendStatus("Chọn <Thêm> và loại chứng từ cần thêm mới", false);
            }
            else
            {
                setEditMode(false);
                sendStatus("Bạn không có quyền thêm mới", false);
            }

            
		}

		private void bmb_PositionChanged(object sender, System.EventArgs e) {
			if (cancelHandlers) return;

			cancelHandlers = true;
			if (bmb.Count == 0) {
				this.lblRecordInfo.Text = "0/0";
			} else {
				this.lblRecordInfo.Text = (bmb.Position +1) +"/" +bmb.Count;
			}

			if (bmb.Position >= 0) {
				buildDgridTS();
			}
			cancelHandlers = false;
		}

		private void TienMatPhieuThuHocphi_RowDeleted(object sender, DataRowChangeEventArgs e) {
            if (ptData.getTable(KeHoachThuHocphiData.TL.TienMatPT).Rows[bmb.Position].GetChildRows("M_D").Length > 0)
            {
                this["TongTien"] = ptData.getTable(KeHoachThuHocphiData.TL.TienMatPT_CT).Compute("Sum(SoTien)", "SoChungTu='" + this["SoChungTu"] + "'");
			} 
            else {
			   this["TongTien"] = 0;
			}
			bmb.EndCurrentEdit();
		}

		private void TienMatPhieuThuHocphi_ColumnChanged(object sender, DataColumnChangeEventArgs e) {

            if (cancelHandlers) return;
			cancelHandlers = true;
            //MessageBox.Show(e.Column.ColumnName);  

			try {
                if (e.Column.ColumnName.ToUpper() == "SOTIEN" || e.Column.ColumnName.ToUpper() == "SOLUONG" || e.Column.ColumnName.ToUpper() == "DONGIA" || e.Column.ColumnName.ToUpper() == "THUESUAT" || e.Column.ColumnName.ToUpper() == "TIGIA")
               {

					double sumSoTien = 0;

                    if (!(e.Row["SoLuong"] is DBNull) && !(e.Row["DonGia"] is DBNull))
                        e.Row["SoTien"] = Convert.ToDouble(e.Row["SoLuong"]) * Convert.ToDouble(e.Row["DonGia"]);


					if (e.Row["SoTien"] is DBNull) e.Row["SoTien"] = 0;

                    double soTien = (double)(decimal)e.Row["SoTien"];
					
                    sumSoTien = soTien;

                    int numOfRow = ptData.getTable(KeHoachThuHocphiData.TL.TienMatPT).Rows[bmb.Position].GetChildRows("M_D").Length;

					if (numOfRow > 0) {
                        sumSoTien = (double)(decimal)ptData.getTable(KeHoachThuHocphiData.TL.TienMatPT_CT).Compute("Sum(SoTien)", "SoChungTu='" + this["SoChungTu"] + "'");
						if (numOfRow == dgridChiTietPT.CurrentCell.RowNumber) {
							sumSoTien += soTien;
						}
					}
					this["TongTien"] = sumSoTien;

                    //Disable nhung textbox ko the sua neu co nhieu dong o chi tiet
                    //txtSoTien.Enabled = !(numOfRow > 1);
                    //txtPhantramDiscount.Enabled = !(numOfRow > 1);
                    //txtSoTienDiscount.Enabled = !(numOfRow > 1); 
                    //cboLyDoThu.Enabled = !(numOfRow > 1);
				
                    bmb.EndCurrentEdit();

				}
			} finally {
				cancelHandlers = false;
			}
             
		}

		#region [ Commond Methods ]

		private void intiDatabinding() {
			this.txtSoChungTu.DataBindings.Add("Text", ptData.getDataSet(), "TienMatPT.SoChungTu");
			this.txtNgayChungTu.DataBindings.Add("Text", ptData.getDataSet(), "TienMatPT.NgayChungTu");
			this.txtNgayChungTu.ActiveDisplayFormat();
            
            this.txtMaNienHoc.DataBindings.Add("Text", ptData.getDataSet(), "TienMatPT.MaNienHoc");
            this.cboLop.DataBindings.Add("SelectedValue", ptData.getDataSet(), "TienMatPT.MaLop");
            this.list_DSHocSinh_Lop.DataBindings.Add("SelectedValue", ptData.getDataSet(), "TienMatPT.MaDoiTac");

            this.txtDienGiai.DataBindings.Add("Text", ptData.getDataSet(), "TienMatPT.DienGiai");
            
            this.txtDotHocPhi.DataBindings.Add("Text", ptData.getDataSet(), "TienMatPT.SoLanTrenInvoice");
            this.txtDotHocPhi.DataBindings["Text"].Parse += new ConvertEventHandler(TienMatPhieuThuHocphi_Parse);
            this.txtDotHocPhi.DataBindings["Text"].Format += new ConvertEventHandler(TienMatPhieuThuHocphi_Format);

            //So tien phai thu (luu vao TONGTIEN)
            this.txtSoTien.DataBindings.Add("Text", ptData.getDataSet(), "TienMatPT.TongTien");
            this.txtSoTien.DataBindings["Text"].Parse += new ConvertEventHandler(TienMatPhieuThuHocphi_Parse);
            this.txtSoTien.DataBindings["Text"].Format += new ConvertEventHandler(TienMatPhieuThuHocphi_Format);
            

            //Ly do thu (dung de dinh khoan)
            this.cboLyDoThu.DataBindings.Add("SelectedValue", ptData.getDataSet(), "TienMatPT.LyDoThuChi");
            this.cboLyDoThu.DataSource = ptData.getTable(KeHoachThuHocphiData.TL.LyDoThuHP);
            this.cboLyDoThu.DisplayMember = "TenHocPhi";
            this.cboLyDoThu.ValueMember = "MaHocPhi";

            this.txtNgayDuKienThu.DataBindings.Add("Text", ptData.getDataSet(), "TienMatPT.NgayDuKienThu");
            this.txtNgayDuKienThu.ActiveDisplayFormat();
     
			dgridChiTietPT.SetDataBinding(ptData.getDataSet(), "TienMatPT.M_D");
		}

		private void TienMatPhieuThuHocphi_Parse(object sender, ConvertEventArgs e) {
			try {
				if (e.Value == null || (string)e.Value == string.Empty) {
					e.Value = DBNull.Value;
				} else {
					e.Value = double.Parse((string)e.Value);
				}
			} catch {
				sendStatus("Bạn vui lòng nhập đúng định dạng số.", true);
			}
		}

        private void TienMatPhieuThuHocphi_Format(object sender, ConvertEventArgs e)
        {
			try {
				if (Convert.IsDBNull(e.Value)) {
					e.Value = "";
				} else {
					e.Value = ((decimal)e.Value).ToString("N0");
				}
			} catch (Exception ex) {
				//sendStatus("Unexpected Error: " +ex.Message, true); //Ko can thiet, gay roi
			}
		}

		DataGridAutoResizeSupporter dgridARS = new DataGridAutoResizeSupporter();
		DataGridStyleFactory dgridSF = new DataGridStyleFactory();

        private void buildDgridTS() {

			// Build based on LyDoThu column
			if (cboLyDoThu.SelectedIndex == -1) {
				return;
			}
            DataRow dr = ptData.getTable(KeHoachThuHocphiData.TL.LyDoThuHP).Rows[cboLyDoThu.SelectedIndex];
			
			DataGridTableStyle ts = new DataGridTableStyle();
            ts.MappingName = ptData.getTable(KeHoachThuHocphiData.TL.TienMatPT_CT).TableName;

			AGridTextBoxColumn agridTC;

            AGridMCComBoBoxColumn colLDT = new AGridMCComBoBoxColumn(ptData.getTable(KeHoachThuHocphiData.TL.TaiKhoan));
			colLDT.MappingName = "TaiKhoanCo";
			colLDT.HeaderText = "TK CO";
            colLDT.DisplayMember = "MaTaiKhoan";
			colLDT.ValueMember = "MaTaiKhoan";
            colLDT.Alignment = HorizontalAlignment.Center;
			colLDT.NullText = "";
			colLDT.Width = 70;
			ts.GridColumnStyles.Add(colLDT);
            
            //Them cot Tieu khoan co1 = Madoitac
            agridTC = new AGridTextBoxColumn();
            agridTC.MappingName = "MaTieukhoanCO1";
            agridTC.HeaderText = "Tiểu khoản";
            agridTC.Alignment = HorizontalAlignment.Center;
            agridTC.NullText = "";
            agridTC.Width = 100;
            ts.GridColumnStyles.Add(agridTC);

            agridTC = new AGridTextBoxColumn();
            agridTC.MappingName = "DienGiaiChiTiet";
            agridTC.HeaderText = "Diễn giải chi tiết";
            agridTC.NullText = "";
            agridTC.Width = 150;
            //agridTC.Format = "N";
            ts.GridColumnStyles.Add(agridTC);

            //So luong
            agridTC = new AGridTextBoxColumn();
            agridTC.MappingName = "SoLuong";
            agridTC.HeaderText = "SL";
            agridTC.NullText = "";
            agridTC.Width = 40;
            agridTC.Format = "N0";
            agridTC.Alignment = HorizontalAlignment.Center;
            ts.GridColumnStyles.Add(agridTC);
            
            //Don gia
            agridTC = new AGridTextBoxColumn();
            agridTC.MappingName = "DonGia";
            agridTC.HeaderText = "Đơn giá";
            agridTC.NullText = "";
            agridTC.Width = 70;
            agridTC.Format = "N0";
            agridTC.Alignment = HorizontalAlignment.Right;
            ts.GridColumnStyles.Add(agridTC);

            //Thanh tien
            agridTC = new AGridTextBoxColumn();
        	agridTC.MappingName = "SoTien";
			agridTC.HeaderText = "Số tiền";
			agridTC.NullText = "";
			agridTC.Width = 80;
			agridTC.Format = "N0";
            agridTC.Alignment = HorizontalAlignment.Right;
			ts.GridColumnStyles.Add(agridTC);

            //Them cot Tieu khoan NO (de theo doi Ngan hang, Tien mat)
            agridTC = new AGridTextBoxColumn();
            agridTC.MappingName = "TaikhoanNO";
            agridTC.HeaderText = "TK NO";
            agridTC.Alignment = HorizontalAlignment.Center;
            agridTC.NullText = "";
            agridTC.Width = 50;
            ts.GridColumnStyles.Add(agridTC);

            //Them cot Tieu khoan NO1
            agridTC = new AGridTextBoxColumn();
            agridTC.MappingName = "MaTieukhoanNO1";
            agridTC.HeaderText = "Tiểu khoản NO";
            agridTC.Alignment = HorizontalAlignment.Center;
            agridTC.NullText = "";
            agridTC.Width = 100;
            ts.GridColumnStyles.Add(agridTC);

			dgridChiTietPT.TableStyles.Clear();
			dgridChiTietPT.TableStyles.Add(ts);
			dgridSF.applyStyle(dgridChiTietPT, DataGridStyleFactory.Styles.SexyStyle);
			dgridChiTietPT.TableStyles[0].AllowSorting = false;

            //Ghi chu
            agridTC = new AGridTextBoxColumn();
            agridTC.MappingName = "GhiChu";
            agridTC.HeaderText = "Ghi chú";
            agridTC.NullText = "";
            agridTC.Width = 300;
            ts.GridColumnStyles.Add(agridTC);
		}

		private void setEditMode(bool edit) {

			cmdAddNew.Enabled = !edit  && DuocQuyenThem ;
			cmdDelete.Enabled = !edit && bmb.Position >= 0 && DuocQuyenXoa ;
			cmdModify.Enabled = !edit && bmb.Position >= 0  && DuocQuyenSua ;
			cmdPrint.Enabled = !edit && bmb.Position >= 0;
			cmdView.Enabled = !edit;
			cmdUpdate.Enabled = edit;
			cmdCancel.Enabled = edit;

			cmdMoveFirst.Enabled = !edit;
			cmdMovePrevious.Enabled = !edit;
			cmdMoveNext.Enabled = !edit;
			cmdMoveLast.Enabled = !edit;

            txtSoChungTu.ReadOnly = true;
			txtNgayChungTu.ReadOnly = !edit;
            txtMaNienHoc.ReadOnly = !edit;
            cboLop.Enabled = edit;
            cboLyDoThu.Enabled = edit;

            txtDotHocPhi.ReadOnly = !edit;
            txtSoTien.ReadOnly = true; //Khoa edit
 			txtDienGiai.ReadOnly = !edit;
			
 			dgridChiTietPT.ReadOnly = !edit;
			cmdXemTK.Enabled = bmb.Position >= 0;
            
		}

		#endregion

		#region [ Command Events ]

		private void cmdAddNew_Click(object sender, System.EventArgs e) {
			cancelHandlers = true;

            if (ptData.createNewRow(GlobalVariable.WSInfo["TienMat.PhieuThuHP.MaLoaiCT", "HP"]))
            {
				bmb.Position = bmb.Count -1;
				setEditMode(true);
                cboLop.Focus();
			}
			cancelHandlers= false;
			bmb_PositionChanged(bmb, e);
			sendStatus("Đang trong trạng thái thêm mới...", false);


            cboLyDoThu.SelectedIndex = -1; 
		}

		private void cmdSave_Click(object sender, System.EventArgs e) {
            
            ep.Clear();

            if (txtSoChungTu.Text == "") return;

            //Kiem tra su giong nhau giua sochungtu va ngaychungtu
            if (txtNgayChungTu.getDateValue(true).Year.ToString().Substring(2, 2) != txtSoChungTu.Text.Substring(2, 2) || txtNgayChungTu.getDateValue(true).Month.ToString("00") != txtSoChungTu.Text.Substring(4, 2))
            {
                MessageBox.Show("Thời gian làm việc không đúng với ngày chứng từ \nBạn phải login vào chương trình với ngày làm việc thuộc tháng " +
                                              txtNgayChungTu.getDateValue(true).Month.ToString() + " năm " + txtNgayChungTu.getDateValue(true).Year.ToString(),
                                              "Chon sai ngay lam viec", MessageBoxButtons.OK, MessageBoxIcon.Information);
                ep.SetError(txtSoChungTu, "Chọn lại ngày làm việc ngay ở màn hình đăng nhập ban đầu để đánh số chứng từ cho đúng");
                return;
            }

            
            if (cboLyDoThu.SelectedIndex == -1)
            {
                ep.SetError(cboLyDoThu, "Vui lòng chọn lý do thu tiền để chúng tôi hạch toán chứng từ");
                cboLyDoThu.Focus();
                showEP = true;
                return;
            }


            //Tinh toan lai các kiểu tiền cho đúng trước khi lưu
            TinhToanTien();

            //Bat dau LU
			// dont regard to this code
			try {
				dgridChiTietPT.CurrentCell = 
					new DataGridCell(dgridChiTietPT.CurrentCell.RowNumber +1, 
					dgridChiTietPT.CurrentCell.ColumnNumber);
			} catch {}

			cancelHandlers = true;
			bmb.EndCurrentEdit();
			if (ptData.update()) {
				setEditMode(false);
                sendStatus("Đã lưu phiếu thu " + txtSoChungTu.Text  , false);
			}
			cancelHandlers = false;
			bmb_PositionChanged(bmb, e);
		}

		private void cmdCancel_Click(object sender, System.EventArgs e) {
            cancelHandlers = true;
            try
            {
                bmb.EndCurrentEdit();
                sendStatus("Bỏ qua, không cập nhật", false);
                DialogResult dr = DialogResult.Yes;
                if (ptData.getTable(KeHoachThuHocphiData.TL.TienMatPT).GetChanges() != null &&
                    ptData.getTable(KeHoachThuHocphiData.TL.TienMatPT_CT).GetChanges() != null)
                {
                    dr = MessageBox.Show(this, RS.CANCEL_UPDATE, RS.CANCEL_UPDATE_CAPTION,
                        MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                }

                if (dr == DialogResult.Yes)
                {
                    cancelHandlers = true;
                    ptData.getDataSet().RejectChanges();
                    cancelHandlers = false;
                    setEditMode(false);
                    bmb_PositionChanged(bmb, e);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            cancelHandlers = false;
		}

		FormView fv = null;
		private void cmdView_Click(object sender, System.EventArgs e) {
            //gridLookUpEdit_txtMaHocSinhView.ClearColumnsFilter();
			if (fv == null) {
                fv = new FormView("Select SoChungtu, convert(varchar, NgayChungtu, 103) as NgayChungTu, HoTen, DienGiai, TongtienUSD, Tigia, TongTien, PhanTramDiscount, TongTienDiscount, ThucThu, isnull(SoChungTuCu, '') as SoChungTuCu, " +
                    "SoHoadon, SerialHoadon, NgayHoadon, UpdateUserID " +
                    "from TienMat WHERE MaLoaiChungTu in ('KH') order by NgayChungTu, SoChungTu ", 
                    GlobalVariable.WSInfo.ConnectionString,
                    GlobalVariable.WSInfo.WorkingDate );
				fv.DateFilterColumns = new string[,] {{"NgayChungTu", "Ngày chứng từ"}, {"UpdateDate", "Ngày cập nhật"}};
                //fv.CollumnFocusInFilterGrid = 2;
			}
			fv.ShowDialog(this);
			if (fv.DialogResult == DialogResult.OK) {
				cancelHandlers = true;
                
                //Truong hop lay phieu cu thi fill ton bo ly do thu (khong loc theo loai chung tu khi chon nhap moi)
                //this.cboLyDoThu.DataSource = ptData.getTable(TienMatPhieuThuHocphiData.TL.LyDoThuHP);

				ptData.initData(fv.SelectedIDs, false);
				setEditMode(false);
                cancelHandlers = false;

				bmb_PositionChanged(bmb, e);
			}			
		}

		private void cmdModify_Click(object sender, System.EventArgs e) {
			if (bmb.Position >= 0) {
				bmb.EndCurrentEdit();
				setEditMode(true);
                sendStatus("Đang trong trạng sửa phiếu thu " + txtSoChungTu.Text  , false);
                //if (ptData.getTable(TienMatPhieuThuHocphiData.TL.TienMatPT).Rows[bmb.Position].GetChildRows("M_D").Length > 1)
                //{
					//
                    //dgridChiTietPT.Visible = false ;
                    //this.Size = this.MinimumSize;
                    //cmdXemTK_Click(cmdXemTK, e);
                    //Disable nhung textbox ko the sua neu co nhieu dong o chi tiet
                    //txtSoTien.Enabled = false;
                    //cboLyDoThu.Enabled = false; 
				//}
			}
		}

		private void cmdDelete_Click(object sender, System.EventArgs e) {
			DialogResult dr = MessageBox.Show(this, RS.DELETE_RECORD, RS.DELETE_RECORD_CAPTION, 
				MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
			if (dr == DialogResult.Yes) {
				cancelHandlers = true;

                //Luu vet (Deleted)
                try
                {
                    SQLHelper.ExecuteScalar(GlobalVariable.WSInfo.ConnectionString, "insert into Tienmat_Deleted select * from TienMat " +
                                                                                "where sochungtu = '" + txtSoChungTu.Text + "'");
                }
                catch { };

				bmb.RemoveAt(bmb.Position);
				ptData.update();
				cancelHandlers = false;
				bmb_PositionChanged(bmb, e);
			}
		}

		private void cmdPrint_Click(object sender, System.EventArgs e) {
            try
            {
         
                cmdPrint.Enabled = false;
                
                //Load report
                ReportDocument rpt = new ReportDocument();
                rpt.Load(Application.StartupPath + "\\Report\\rpt_TienMat_PhieuThu.rpt");

                //Set connection
                PublicFunction.SetDBLogonForReport(rpt);

                //Set parameter
                PublicFunction.SetParameter(rpt,"@Sochungtu", txtSoChungTu.Text);
                PublicFunction.SetParameter(rpt,"pBangchu", ReportUtilities.ReportUtilities.g_Trans_VietNam(Double.Parse(txtSoTien.Text), "đồng", true));
                PublicFunction.SetParameter(rpt,"pNguoiLapBieu", GlobalVariable.WSInfo.UserName);
                PublicFunction.SetParameter(rpt,"pThuquy", GlobalVariable.WSInfo["Sys.UserName.Thuquy"]);
                PublicFunction.SetParameter(rpt,"pKetoantruong", GlobalVariable.WSInfo["Sys.UserName.KetoanTruong"]);
                PublicFunction.SetParameter(rpt,"pGiamDoc", GlobalVariable.WSInfo["Sys.UserName.Giamdoc"]);

                //View report
                frmPrintPreview frmPP = new frmPrintPreview(rpt);
                frmPP.ShowDialog();
                frmPP.Dispose();

                rpt.Dispose();
                cmdPrint.Enabled = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
		}


		#endregion

        private void cmdXemTK_Click(object sender, System.EventArgs e) {
            
            ep.Clear();
            showEP = false;

			if (!cmdAddNew.Enabled && cboLyDoThu.SelectedIndex == -1) {
				ep.SetError(cboLyDoThu, "Bạn vui lòng chọn lý do thu !.");
				cboLyDoThu.Focus();
				showEP = true;
				return;
			}
             
            if (!cmdAddNew.Enabled && txtSoTien.Text.Trim() == "0") {
				ep.SetError(txtSoTien, "Bạn vui lòng nhập số tiền !.");
				txtSoTien.Focus();
				showEP = true;
				return;
			}
	
 
			dgridChiTietPT.Visible = !dgridChiTietPT.Visible;
			if (dgridChiTietPT.Visible) {
				this.Height += 120;
         	} else {
				this.Size = this.MinimumSize;
				this.WindowState = FormWindowState.Normal;
			}
		}


        bool showEP = false;

	
		private void TienMatPhieuThuHocphi_Click(object sender, System.EventArgs e) {
			cancelHandlers = false;
		}

		private object this[string colName] {
            get { return ptData.getTable(KeHoachThuHocphiData.TL.TienMatPT).Rows[bmb.Position][colName]; }
            set { ptData.getTable(KeHoachThuHocphiData.TL.TienMatPT).Rows[bmb.Position][colName] = value; }
		}

		

		private void TienMatPhieuThuHocphi_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) {
			if (e.KeyCode == Keys.Enter) {
				this.SelectNextControl(this.ActiveControl, true, true, true, true);
			} else if (e.KeyCode == Keys.Escape) {
				this.SelectNextControl(this.ActiveControl, true, false, true, true);
			}
		}

		private void cmdMoveFirst_Click(object sender, System.EventArgs e) {
			cancelHandlers = true;
			if (bmb != null && bmb.Count > 0) {
				bmb.Position = 0;
			}
			cancelHandlers = false;
			bmb_PositionChanged(bmb, e);
		}

		private void cmdMovePrevious_Click(object sender, System.EventArgs e) {
			cancelHandlers = true;
			if (bmb != null && bmb.Position > 0) {
				bmb.Position -= 1;
			}
			cancelHandlers = false;
			bmb_PositionChanged(bmb, e);
		}

		private void cmdMoveLast_Click(object sender, System.EventArgs e) {
			cancelHandlers = true;
			if (bmb != null && bmb.Count > 0) {
				bmb.Position = bmb.Count -1;
			}
			cancelHandlers = false;
			bmb_PositionChanged(bmb, e);
		}

		private void cmdMoveNext_Click(object sender, System.EventArgs e) {
			cancelHandlers = true;
			if (bmb != null && bmb.Position < bmb.Count -1) {
				bmb.Position += 1;
			}
			cancelHandlers = false;
			bmb_PositionChanged(bmb, e);
		}

		private void sendStatus(string msg) {
			sendStatus(msg, false);
		}

		private void picboxHelp_Click(object sender, System.EventArgs e) {
		
		}

		private void cmdNote_Click(object sender, System.EventArgs e) {
			SimpleObjectNote son = new SimpleObjectNote(GlobalVariable.WSInfo.ConnectionString,
				this.Text, GlobalVariable.WSInfo.UserID);
			son.ShowDialog(this);
		}
	
		private void sendStatus(string msg, bool error) {
			if (error) {
				lblStatus.ForeColor = Color.Red;
				lblStatus.Text = msg;
			} else {
				lblStatus.ForeColor = Color.Black;
				lblStatus.Text = msg;
			}
		}

  
        
        private void cboLyDoThu_Validated(object sender, EventArgs e)
        {
            if (cboLyDoThu.SelectedIndex == -1)
            {
                return;
            }
            ep.Clear();
            showEP = false;

            if (cboLyDoThu.Text.IndexOf("hàng tháng") > 0)
            {
                txtDotHocPhi.Text = txtNgayChungTu.getDateValue().Month.ToString();
                txtThangHocPhi_Validating(null, null);  //Thà chạy ở đây chứ ko viết trong TextChange()
            }
            else
                txtDotHocPhi.Text = "";

            //int Index = cboDonViNopTien.SelectedIndex;
            //txtDienGiai.Text = ((string)txtDienGiai.Tag).Replace("<LyDoThu>", cboLyDoThu.Text).Replace("<TenDonVi>", txtHoTenNguoiNopTien.Text + ", lớp " +
            //                                    ((DataRowView)gridLookUpEdit_txtMaHocSinh.GetSelectedDataRow())["MaLop"].ToString()).Replace(" hàng tháng ", " tháng thứ " + txtThangHocPhi.Text + " ");  //Them Lop vao dien giai

            txtDienGiai.Text = ((DataRowView)cboLyDoThu.Items[cboLyDoThu.SelectedIndex])["DienGiaiMaHocPhi"].ToString();

            string strMaKhoi = ((DataTable)list_DSHocSinh_Lop.DataSource).Rows[list_DSHocSinh_Lop.SelectedIndex]["MaKhoi"].ToString();

            // Gán tài khoản có mặc định cho detail
            try
            {
                if (ptData.getTable(KeHoachThuHocphiData.TL.TienMatPT_CT) != null)
                    ptData.getTable(KeHoachThuHocphiData.TL.TienMatPT_CT).Clear();
                ptData.getTable(KeHoachThuHocphiData.TL.TienMatPT_CT).AcceptChanges();

                // Add a default row to detail
                SqlDataReader HV_DataReader = SQLHelper.ExecuteReader(GlobalVariable.WSInfo.ConnectionString,
                                                    "SELECT MaTaiKhoan, DienGiai, SoTien_" + strMaKhoi + " as SoTien FROM DM_HOCPHI_CHITIET " +
                                                    "WHERE  MaHocPhi = '" + cboLyDoThu.SelectedValue + "' and SoTien_" + strMaKhoi + " <> 0 ");

                while (HV_DataReader.Read())
                {
                    try
                    {
                        DataRow dr = ptData.getTable(KeHoachThuHocphiData.TL.TienMatPT_CT).NewRow();
                        dr["SoChungTu"] = txtSoChungTu.Text;
                        dr["TaikhoanCo"] = HV_DataReader["MaTaiKhoan"] ;
                        dr["MaTieukhoanCo1"] = list_DSHocSinh_Lop.SelectedValue;
                        dr["DonGia"] = HV_DataReader["SoTien"]; //  Double.Parse(txtSoTien.Text);
                        dr["DienGiaiChiTiet"] = HV_DataReader["DienGiai"];
                        dr["MaTieukhoanNo1"] = list_DSHocSinh_Lop.SelectedValue;
                        
                        ptData.getTable(KeHoachThuHocphiData.TL.TienMatPT_CT).Rows.Add(dr);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                bmb.EndCurrentEdit();
            }
            catch (Exception ex) { MessageBox.Show(ex.Message) ; }

            cancelHandlers = true;

            cboLyDoThu.Tag = cboLyDoThu.SelectedIndex;

            buildDgridTS();

            cancelHandlers = false;

        }

        
        protected CNCSoft.EData.VoucherNoGenerator vg;

        
        
        private void cmdAddNew_Click_1(object sender, EventArgs e)
        {

            cancelHandlers = true;

            try
            {
                string strPrefixPhieuThuHocPhi = "KH";
                if (ptData.createNewRow(strPrefixPhieuThuHocPhi))
                {
                    bmb.Position = bmb.Count - 1;
                    ptData.getTable(KeHoachThuHocphiData.TL.TienMatPT).Rows[bmb.Position]["MaLoaiChungTu"] = strPrefixPhieuThuHocPhi;
                    setEditMode(true);
                    cboLop.Focus();
                }
                cancelHandlers = false;
                bmb_PositionChanged(bmb, e);
                sendStatus("Đang trong trạng thái thêm mới...", false);


            }
            catch { }

        }


        private void txtThangHocPhi_Validating(object sender, CancelEventArgs e)
        {
            if (txtDotHocPhi.Text == "") return;

            /*  CHua biet thang HP danh so kieu gi
            int st = Convert.ToInt16(txtThangHocPhi.Text);
               
            if (st > 12 || st < 1)
            {
                e.Cancel = true;
                return;
            }
            */
            
            //Lay SoDuThangTruoc
            
            /*
            try
            {
                txtDienGiai.Text = ((string)txtDienGiai.Tag).Replace("<LyDoThu>", cboLyDoThu.Text).Replace("<TenDonVi>", txtHoTenNguoiNopTien.Text + ", lớp " +
                                                    ((DataRowView)gridLookUpEdit_txtMaHocSinh.GetSelectedDataRow())["MaLop"].ToString()).Replace(" hàng tháng ", " tháng thứ " + txtThangHocPhi.Text + " ");  //Them Lop vao dien giai
            }
            catch { }

            //double dSoDuThangTruocfromForm = txtSoDuThangTruoc.Text =="" ? 0 : Convert.ToDouble(txtSoDuThangTruoc.Text);
            
            //Tinh toan so du cua thang truoc (SoDuThangNay cua Thang truoc chinh la SoduThangTruoc cua thang nay)
            int intThangTruoc = Convert.ToInt16(txtThangHocPhi.Text) - 1;
            object oSoduThangTruoc = SQLHelper.ExecuteScalar(GlobalVariable.WSInfo.ConnectionString, "SELECT SoDuThangNay FROM TIENMAT WHERE MaDoiTac = '" + gridLookUpEdit_txtMaHocSinh.EditValue + "' " +
                                                                                                                            "AND SoLanTrenInvoice = " + intThangTruoc);
            double  dSoDuThangTruocFromData = Convert.ToDouble(oSoduThangTruoc);
            //Tim thay so du la gan gia tri (khong can biet NSD co nhap hay ko)
            if (oSoduThangTruoc != null)
            {
                txtSoDuThangTruoc.Text = dSoDuThangTruocFromData.ToString("N");
            }
            else
            {
                MessageBox.Show("Chưa có thu tháng trước nên chương trình sẽ không quan tâm đến \n\"SỐ DƯ THÁNG TRƯỚC\". \n\nBạn có thể nhập bằng tay cho Số dư của tháng trước" +
                                "\n (kể từ tháng sau trở đi, chương trình sẽ tự động tính toán cho giá trị này dựa vào số dư của tháng trước và số tiền phải nộp, đã nộp của tháng tiếp theo)"
                            ,"Nhắc nhở!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtSoDuThangTruoc.Text = "0";
            }
             * */

        }

       
        
        private void gridLookUpEdit_txtMaHocSinh_Validated(object sender, EventArgs e)
        {
            try
            {
                //Ly do thu (dung de dinh khoan)
                DataTable dt = new DataTable();
                //Tuy theo CHEDO cua HS ma load nhung khoan thu va so tien tuong ung
                //if (cboDonViNopTien.SelectedIndex >= 0)
                //SQLHelper.Fill(dt, GlobalVariable.WSInfo.ConnectionString, "Select * from DM_HOCPHI " +
                //                                            "Where LoaiHocPhi =  '" + ((DataRowView)gridLookUpEdit_txtMaHocSinh.GetSelectedDataRow())["MaCheDo"].ToString() + "'");
                this.cboLyDoThu.DataSource = dt;
                //cboLyDoThu.DisplayMember = "TenHocPhi";
                //cboLyDoThu.ValueMember = "MaHocPhi";
                cboLyDoThu.SelectedIndex = -1;
            }
            catch { };
        }

        
        private void cboLop_SelectedIndexChanged(object sender, EventArgs e)
        {

            try
            {
                if (cboLop.SelectedIndex == -1) return;
                
                DataTable dt = new DataTable();
                SQLHelper.Fill(dt, GlobalVariable.WSInfo.ConnectionString, "SELECT MaHocTap, HOCSINH_LOP.MaHocSinh, Holot + ' ' + Ten as HoTen, MaCheDo, MaKhoi FROM HOCSINH_LOP " +
                                                    "JOIN HOCSINH ON HOCSINH_LOP.MaHocSinh = HOCSINH.MaHocSinh " +
                                                    "JOIN DM_LOP ON HOCSINH_LOP.MaLop = DM_LOP.MaLop " +
                                                    "WHERE  HOCSINH_LOP.MaLop = '" + cboLop.SelectedValue + "' ORDER BY STT_SoCai  ");
                list_DSHocSinh_Lop.DataSource = dt;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }


        private void txtSoTienThucThu_TextChanged(object sender, EventArgs e)
        {
            TinhToanTien();
        }

        private void txtSoDuThangTruoc_TextChanged(object sender, EventArgs e)
        {
            TinhToanTien();
        }


        private void TinhToanTien()
        {
            //double dSoTienPhaiThu = txtSoTien.Text == "" ? 0 : Convert.ToDouble(txtSoTien.Text);
            //double dSoTienThucThu = txtSoTienThucThu.Text == "" ? 0 : Convert.ToDouble(txtSoTienThucThu.Text);
            //double dSoDuThangTruoc = txtSoDuThangTruoc.Text == "" ? 0 : Convert.ToDouble(txtSoDuThangTruoc.Text);

            //double dSoDuThangNay = (dSoDuThangTruoc + dSoTienThucThu) - dSoTienPhaiThu;

            //txtSoDuThangNay.Text = dSoDuThangNay.ToString("N0");
        }

        private void txtMaNienHoc_Validated(object sender, EventArgs e)
        {
            
        }

        private void txtMaNienHoc_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (txtMaNienHoc.Text == "") return;

                DataTable dt = new DataTable();
                SQLHelper.Fill(dt, GlobalVariable.WSInfo.ConnectionString, "SELECT * FROM DM_LOP WHERE MaNienHoc = '" + txtMaNienHoc.Text + "' Order by MaKhoi, STT");

                cboLop.DataSource = dt;
                cboLop.DisplayMember = "TenLop";
                cboLop.ValueMember = "MaLop";
            }
            catch (Exception ex)
            { MessageBox.Show(ex.Message); }
        }

        private void txtThangHocPhi_TextChanged(object sender, EventArgs e)
        {

        }

        private void list_DSHocSinh_Lop_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (list_DSHocSinh_Lop.SelectedIndex < 0) return;

            try
            {
                //Ly do thu (dung de dinh khoan)
                DataTable dt = new DataTable();
                //Tuy theo CHEDO cua HS ma load nhung khoan thu va so tien tuong ung
                
                SQLHelper.Fill(dt, GlobalVariable.WSInfo.ConnectionString, "Select * from DM_HOCPHI " +
                                                            "Where LoaiHocPhi =  '" + ((DataTable)list_DSHocSinh_Lop.DataSource).Rows[list_DSHocSinh_Lop.SelectedIndex]["MaCheDo"].ToString() + "'");

                //MessageBox.Show( list_DSHocSinh_Lop.Text + ": " + ((DataTable)list_DSHocSinh_Lop.DataSource).Rows[list_DSHocSinh_Lop.SelectedIndex]["MaCheDo"].ToString());

                this.cboLyDoThu.DataSource = dt;
                cboLyDoThu.DisplayMember = "TenHocPhi";
                cboLyDoThu.ValueMember = "MaHocPhi";
                //cboLyDoThu.SelectedIndex = -1;

                //cancelHandlers = true;
                //ptData.initData("('" + cboLyDoThu.SelectedValue.ToString()+ "')", false);
                //setEditMode(false);
                //cancelHandlers = false;

                //bmb_PositionChanged(bmb, e);

            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
            };
        }

       
        
        
       
	}
}